home *** CD-ROM | disk | FTP | other *** search
/ Mastering Internet Develo…oft ActiveX Technologies / Mastering Internet Development with ActiveX (1996)(Microsoft).iso / labs / lab09 / solution / frmleads.frm (.txt) < prev    next >
Visual Basic Form  |  1996-07-16  |  7KB  |  231 lines

  1. VERSION 4.00
  2. Begin VB.Form frmLeads 
  3.    Caption         =   "Sales Leads"
  4.    ClientHeight    =   5940
  5.    ClientLeft      =   1725
  6.    ClientTop       =   1785
  7.    ClientWidth     =   6690
  8.    Height          =   6630
  9.    Left            =   1665
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5940
  12.    ScaleWidth      =   6690
  13.    Top             =   1155
  14.    Width           =   6810
  15.    Begin SHDocVwCtl.WebBrowser dwnLoad 
  16.       Height          =   735
  17.       Left            =   240
  18.       TabIndex        =   1
  19.       Top             =   3360
  20.       Visible         =   0   'False
  21.       Width           =   1215
  22.       Object.Height          =   49
  23.       Object.Width           =   81
  24.       AutoSize        =   0
  25.       ViewMode        =   1
  26.       AutoSizePercentage=   0
  27.       AutoArrange     =   -1  'True
  28.       NoClientEdge    =   -1  'True
  29.       AlignLeft       =   0   'False
  30.       Location        =   "C:\WINDOWS\SYSTEM\BLANK.HTM"
  31.    End
  32.    Begin ComctlLib.ListView lstLeads 
  33.       Height          =   2295
  34.       Left            =   480
  35.       TabIndex        =   0
  36.       Top             =   360
  37.       Width           =   4695
  38.       _Version        =   65536
  39.       _ExtentX        =   8281
  40.       _ExtentY        =   4048
  41.       _StockProps     =   205
  42.       ForeColor       =   -2147483640
  43.       BackColor       =   -2147483643
  44.       Appearance      =   1
  45.       HideSelection   =   0   'False
  46.       Icons           =   ""
  47.       LabelWrap       =   0   'False
  48.       SmallIcons      =   ""
  49.       View            =   3
  50.       NumItems        =   6
  51.       i1              =   "frmLeads.frx":0000
  52.       i2              =   "frmLeads.frx":00B8
  53.       i3              =   "frmLeads.frx":0174
  54.       i4              =   "frmLeads.frx":0224
  55.       i5              =   "frmLeads.frx":02DC
  56.       i6              =   "frmLeads.frx":0394
  57.    End
  58.    Begin VB.Menu mnuFile 
  59.       Caption         =   "File"
  60.       Begin VB.Menu mnuFileRead 
  61.          Caption         =   "&Read Leads List"
  62.       End
  63.       Begin VB.Menu mnuLine1 
  64.          Caption         =   "-"
  65.       End
  66.       Begin VB.Menu mnuFileSend 
  67.          Caption         =   "&Send E-mail"
  68.       End
  69.       Begin VB.Menu mnuFileWebIE 
  70.          Caption         =   "Open Web Site in &Internet Explorer"
  71.       End
  72.       Begin VB.Menu mnuFileWebVB 
  73.          Caption         =   "Open Web Site in &VB"
  74.       End
  75.       Begin VB.Menu mnuLine2 
  76.          Caption         =   "-"
  77.       End
  78.       Begin VB.Menu mnuExit 
  79.          Caption         =   "E&xit"
  80.       End
  81.    End
  82.    Begin VB.Menu mnuPopup 
  83.       Caption         =   "lstPopup"
  84.       Visible         =   0   'False
  85.       Begin VB.Menu mnuPopEmail 
  86.          Caption         =   "&Send E-mail"
  87.       End
  88.       Begin VB.Menu mnuPopWebIE 
  89.          Caption         =   "Open &Web Site in Internet Explorer"
  90.       End
  91.       Begin VB.Menu mnuPopWebVB 
  92.          Caption         =   "Open Web Site in &VB"
  93.       End
  94.    End
  95. Attribute VB_Name = "frmLeads"
  96. Attribute VB_Creatable = False
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. Dim MailSession As Object
  100. Private Sub OpenWebInIE()
  101.     Dim strWeb As String
  102.     Dim browser As InternetExplorer
  103.     'read the web site address (subitem 5) from the selected list entry
  104.     strWeb = lstLeads.SelectedItem.SubItems(5)
  105.     'start up IE
  106.     Set browser = CreateObject("InternetExplorer.Application")
  107.     browser.Visible = True
  108.     browser.Navigate strWeb
  109. End Sub
  110. Private Sub OpenWebInVB()
  111.     frmBrowse.txtAddress.Text = lstLeads.SelectedItem.SubItems(5)
  112.     frmBrowse.Show
  113.     frmBrowse.cmdGo_Click
  114. End Sub
  115. Private Sub SendEmail()
  116. On Error GoTo badlogon
  117.     Dim mailMsg As Object
  118.     Dim mailRecip As Object
  119.     'logon if not already logged on
  120.     If MailSession Is Nothing Then
  121.         Set MailSession = CreateObject("Mapi.session")
  122.         If Not MailSession Is Nothing Then
  123.             MailSession.Logon
  124.         End If
  125.     End If
  126.     Set mailMsg = MailSession.Inbox.Messages.Add
  127.     mailMsg.subject = "Main St. Market Information"
  128.     Set mailRecip = mailMsg.Recipients.Add
  129.     mailRecip.Name = lstLeads.SelectedItem.SubItems(4)
  130.     mailRecip.Type = mapiTo
  131.     mailMsg.Update
  132.     mailMsg.Send ShowDialog:=True
  133.     Exit Sub
  134. badlogon:
  135.     'trying to use mail when something went wrong
  136.     Exit Sub
  137. End Sub
  138. Private Sub FillList()
  139. 'read info from a file and fill in lstLeads
  140.     Dim fhandle As Integer
  141.     Dim filename As String
  142.     Dim strSalesman As String
  143.     Dim strCustomer As String
  144.     Dim strCompany As String
  145.     Dim strPhone As String
  146.     Dim strEmail As String
  147.     Dim strWeb As String
  148.     Dim itmX As ListItem
  149.     fhandle = FreeFile
  150.     filename = App.Path & "\leads.mlt"
  151.     Open filename For Input As fhandle
  152.     Do While Not EOF(1) ' Loop until end of file.
  153.         'read line of information
  154.         Input #fhandle, strSalesman, strCustomer, strCompany, strPhone, strEmail, strWeb
  155.         'add to listview control
  156.         Set itmX = lstLeads.ListItems.Add()
  157.         itmX.Text = strSalesman
  158.         itmX.SubItems(1) = strCustomer
  159.         itmX.SubItems(2) = strCompany
  160.         itmX.SubItems(3) = strPhone
  161.         itmX.SubItems(4) = strEmail
  162.         itmX.SubItems(5) = strWeb
  163.     Loop
  164.     Close fhandle
  165.     'enable menu items
  166.     EnableMenuItems True
  167. End Sub
  168. Sub ClearList()
  169.     Dim i
  170.     For i = 1 To lstLeads.ListItems.Count
  171.         lstLeads.ListItems.Remove 1
  172.     Next
  173. End Sub
  174. Sub EnableMenuItems(enable As Boolean)
  175.     mnuFileSend.Enabled = enable
  176.     mnuFileWebIE.Enabled = enable
  177.     mnuFileWebVB.Enabled = enable
  178. End Sub
  179. Private Sub Form_Load()
  180.     EnableMenuItems False
  181. End Sub
  182. Private Sub Form_Resize()
  183.     Dim c As ColumnHeader
  184.     Dim hdrWidth As Integer
  185.     'make lstLeads the size of frmLeads
  186.     lstLeads.Move 0, 0, frmLeads.ScaleWidth, frmLeads.ScaleHeight
  187.     'split the columns equally
  188.     hdrWidth = (lstLeads.Width / 8)
  189.     For Each c In lstLeads.ColumnHeaders
  190.         c.Width = hdrWidth
  191.     Next
  192. End Sub
  193. Private Sub Form_Unload(Cancel As Integer)
  194.     'if we've logged onto mail this session, logoff
  195.     If Not MailSession Is Nothing Then
  196.         MailSession.Logoff
  197.     End If
  198. End Sub
  199. Private Sub lstLeads_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  200.     'show popup menu on right mouse click
  201.     If Button = vbRightButton And lstLeads.ListItems.Count <> 0 Then
  202.         'make sure user clicked on an item
  203.         frmLeads.PopupMenu mnuPopup, vbPopupMenuRightButton
  204.     End If
  205. End Sub
  206. Private Sub mnuExit_Click()
  207.     Unload frmLeads
  208. End Sub
  209. Private Sub mnuFileRead_Click()
  210.     ClearList
  211.     FillList
  212. End Sub
  213. Private Sub mnuFileSend_Click()
  214.     SendEmail
  215. End Sub
  216. Private Sub mnuFileWebIE_Click()
  217.     OpenWebInIE
  218. End Sub
  219. Private Sub mnuFileWebVB_Click()
  220.     OpenWebInVB
  221. End Sub
  222. Private Sub mnuPopEmail_Click()
  223.     SendEmail
  224. End Sub
  225. Private Sub mnuPopWebIE_Click()
  226.     OpenWebInIE
  227. End Sub
  228. Private Sub mnuPopWebVB_Click()
  229.     OpenWebInVB
  230. End Sub
  231.